package cn.xfyun.example.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.jdbc.DataSourceBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.core.JdbcTemplate;

import javax.sql.DataSource;

@Configuration
public class AppConfig {

    // MySQL 配置
    @Value("${spring.datasource.url}")
    private String dbUrl;

    @Value("${spring.datasource.username}")
    private String dbUsername;

    @Value("${spring.datasource.password}")
    private String dbPassword;

    @Value("${spring.datasource.driver-class-name}")
    private String dbDriverClass;

    // Redis 配置
    @Value("${redis.host}")
    private String redisHost;

    @Value("${redis.port}")
    private int redisPort;

    @Value("${redis.password}")
    private String redisPassword;

    @Value("${third_party.chatdoc.appid}")
    private String appid;

    @Value("${third_party.chatdoc.apisecret}")
    private String apisecret;

    @Value("${third_party.chatdoc.apiKey}")
    private String apiKey;

    /**
     * 创建 DataSource Bean
     */
    @Bean
    public DataSource dataSource() {
        return DataSourceBuilder.create()
                .url(dbUrl)
                .username(dbUsername)
                .password(dbPassword)
                .driverClassName(dbDriverClass)
                .build();
    }

    /**
     * 创建 JdbcTemplate Bean
     */
    @Bean
    public JdbcTemplate jdbcTemplate(DataSource dataSource) {
        return new JdbcTemplate(dataSource);
    }

    // Getter 方法
    public String getDbUrl() { return dbUrl; }
    public String getDbUsername() { return dbUsername; }
    public String getDbPassword() { return dbPassword; }
    public String getDbDriverClass() { return dbDriverClass; }
    public String getRedisHost() { return redisHost; }
    public int getRedisPort() { return redisPort; }
    public String getRedisPassword() { return redisPassword; }
    public String getAppid() { return appid; }
    public String getApisecret() { return apisecret; }

    public String getSparkApiKey() { return apiKey; }
    public String getSparkApiSecret() { return apisecret; }

    public String getSparkAppid() { return appid;}
}
